import 'package:flutter/material.dart';

class ScanLine extends StatefulWidget {
  ScanLine({this.color = const Color.fromARGB(255, 255, 20, 147)});
  final Color color;
  @override
  _ScanLineState createState() => _ScanLineState();
}

class _ScanLineState extends State<ScanLine> with TickerProviderStateMixin {
  AnimationController? animationController;
  Animation<double>? animation;

  @override
  void initState() {
    super.initState();

    animationController = AnimationController(
        duration: const Duration(milliseconds: 5000), vsync: this);
    animation = Tween<double>(begin: -1, end: 1).animate(animationController!);
    animationController?.repeat();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  void deactivate() {
    animationController?.dispose();
    super.deactivate();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: animation!,
      builder: (BuildContext context, Widget? child) {
        return Container(
          alignment: Alignment(0.0, animation!.value),
          child: Container(
            height: 2,
            decoration: BoxDecoration(
              gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: <Color>[
                    widget.color.withAlpha(0x00),
                    widget.color.withAlpha(0x94),
                    widget.color,
                    widget.color.withAlpha(0x94),
                    widget.color.withAlpha(0),
                  ]),
            ),
          ),
        );
      },
    );
  }
}
